package com.lesso.cyg.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.cyg.sunflower.domain.repository.AttendanceRuleRepository;
import com.lesso.cyg.sunflower.infra.assembler.AttendanceRuleAssembler;
import com.lesso.cyg.sunflower.pojo.dto.AttendanceRuleDTO;
import com.lesso.cyg.sunflower.pojo.dto.AttendanceRuleQueryDTO;
import com.lesso.cyg.sunflower.model.AttendanceRule;
import org.springframework.stereotype.Service;

/**
 * AttendanceRuleDomainService
 *
 * @author cyg
 * @since 2025-07-02
 */
@Service
public class AttendanceRuleDomainService {

    private final AttendanceRuleRepository attendanceRuleRepository;

    public AttendanceRuleDomainService(AttendanceRuleRepository attendanceRuleRepository) {
        this.attendanceRuleRepository = attendanceRuleRepository;
    }

    public Integer save(AttendanceRuleDTO dto) {
        return attendanceRuleRepository.save(AttendanceRuleAssembler.INSTANCE.dtoToEntity(dto));
    }

    public void deleteById(Long id) {
        attendanceRuleRepository.removeById(id);
    }

    public Integer update(AttendanceRuleDTO dto) {
        return attendanceRuleRepository.update(AttendanceRuleAssembler.INSTANCE.dtoToEntity(dto));
    }

    public Page<AttendanceRuleDTO> page(AttendanceRuleQueryDTO dto) {
        // 实现具体的查询逻辑，根据 dto 中的条件查询
        Page<AttendanceRule> entityPage = new Page<>(dto.getPage().getCurrent(), dto.getPage().getSize());
        // attendanceRuleRepository.selectPage(entityPage, wrapper);
        Page<AttendanceRuleDTO> dtoPage = new Page<>();
        dtoPage.setRecords(AttendanceRuleAssembler.INSTANCE.entityListToDtoList(entityPage.getRecords()));
        return dtoPage;
    }
}